//
//  HLTgonghuititleCollectionViewCell.m
//  huiliantong
//
//  Created by hlt on 15/10/22.
//  Copyright © 2015年 hlt. All rights reserved.
//

#import "HLTgonghuititleCollectionViewCell.h"
#import "HLTzhanneixinTableViewController.h"
@implementation HLTgonghuititleCollectionViewCell

- (void)awakeFromNib {
    // Initialization code
}


-(void) initview
{
    
    UIView *view1=[[UIView alloc] initWithFrame:self.parent.view.bounds];
    view1.backgroundColor=[UIColor grayColor];
    view1.alpha=0.4;
    [self.parent.view addSubview:view1];
    MONActivityIndicatorView *indicatorView = [[MONActivityIndicatorView alloc] init];
    indicatorView.delegate = self;
    indicatorView.numberOfCircles = 3;
    indicatorView.radius = 20;
    indicatorView.internalSpacing = 3;
    indicatorView.center = self.parent.view.center;
    [indicatorView startAnimating];
    [self.parent.view addSubview:indicatorView];
    
    Account *acc=[[AccountTool sharedAccountTool] currentAccount];
    
    
    NSString *url=[chaxungonghui stringByAppendingFormat:@"&username=%@&card_num=%@",acc.custPhone,acc.cardNo];
    //将url转换一下格式，否则请求的格式就不兼容
    //    url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    [HLTNetWorkingtool getdic:url success:^(NSDictionary *ary) {
        
        [indicatorView stopAnimating];
        [view1 removeFromSuperview];

        
        
        
        if (ary[@"name"]) {
            
            self.huanyin.text=[NSString stringWithFormat:@"你好,%@",ary[@"name"]];
            
            self.suoshugonghui.text=ary[@"gonghui"];
        }
        else
        {
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:ary[@"msg"] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"好", nil];
            [alert show];
            
            [self.parent.navigationController popViewControllerAnimated:YES];
            
            
        }
        
        
        
    } faliure:^(NSString *error) {
        [indicatorView stopAnimating];
        [view1 removeFromSuperview];

        
    }];

    
    self.userid.text=acc.custPhone;
    
    
    self.huanyin.text=[NSString stringWithFormat:@"你好，%@",acc.custName];
    
    if ([acc.cardNo isEqual:@""]) {
        //        self.yue.hidden=YES;
        self.yue.text=@"无汇支付卡";
        self.bangdingkahao.text=@"您未绑定工会卡,请选择卡绑定功能进行绑定";
        
        
    }
    else{
        self.yue.text= [NSString stringWithFormat:@"余额:%@",acc.YKTCardBalance];
        
        self.bangdingkahao.text= [NSString stringWithFormat:@"卡   号:%@",acc.cardNo];
    }
    
    
    
    
}



- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        // 初始化时加载collectionCell.xib文件 这个是把这个xib文件全部加载了，然后取第一个
        NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"HLTgonghuititleCollectionViewCell" owner:self options:nil];
        
        // 如果路径不存在，return nil
        if (arrayOfViews.count < 1)
        {
            return nil;
        }
        // 如果xib中view不属于UICollectionViewCell类，return nil
        if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]])
        {
            return nil;
        }
        // 加载nib
        self = [arrayOfViews objectAtIndex:0];
    }
    return self;
}


- (IBAction)cancel:(id)sender {
    
    
    
    Account *acc=[[AccountTool sharedAccountTool] currentAccount];
    
    //退出登录
    [[AccountTool sharedAccountTool] tuichu:acc];
    
    [self.parent viewWillDisappear:YES];
    [self.parent viewWillAppear:YES];
    
    
    
    
}



//跳转到消息界面
- (IBAction)xiaoxi:(id)sender {
    
    
    Account *acc=[[AccountTool sharedAccountTool ]currentAccount];
    NSString *url=[myfriend stringByAppendingFormat:@"&username=%@",acc.custPhone];
    //将url转换一下格式，否则请求的格式就不兼容
    //    url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    [HLTNetWorkingtool getary:url success:^(NSArray *ary) {
        //        HLTFriendsTableViewController *vc=[[HLTFriendsTableViewController alloc]init];
        //        vc.friendlist=ary;
        //        vc.parent=self.parent;
        //        [self.parent.navigationController pushViewController:vc animated:YES]; //跳转到下一页面
        
        
        UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        HLTzhanneixinTableViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"HLTzhanneixinTableViewController"];
        
        [self.parent.navigationController pushViewController:vc animated:YES]; //跳转到下一页面
        
        
        
    } faliure:^(NSString *error) {
        
        
    }];
    
    
}


#pragma mark - MONActivityIndicatorViewDelegate Methods

- (UIColor *)activityIndicatorView:(MONActivityIndicatorView *)activityIndicatorView
      circleBackgroundColorAtIndex:(NSUInteger)index {
    CGFloat red   = (arc4random() % 256)/255.0;
    CGFloat green = (arc4random() % 256)/255.0;
    CGFloat blue  = (arc4random() % 256)/255.0;
    CGFloat alpha = 1.0f;
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}



@end
